import 'dart:io';

/// 运行 intl_utils 生成代码
/// 如果没有安装 intl_utils，会自动安装
Future<void> runIntlUtilsPackage([bool install = true]) async {
  final result = Process.runSync('dart', ['pub', 'global', 'list']);
  print(result.stdout);
  final stdout = result.stdout as String?;
  if (stdout == null || !stdout.contains('intl_utils')) {
    if (!install) {
      throw Exception('intl_utils not installed');
    }
    print('install intl_utils');
    final result = Process.runSync('dart', ['pub', 'global', 'activate', 'intl_utils']);
    print(result.stdout);
  }
  print('run intl_utils:generate');
  Process.runSync(
    'dart',
    ['pub', 'global', 'run', 'intl_utils:generate'],
    workingDirectory: Directory.current.path,
  );
}
